from coin.exchange.huobi.kr_rest.native_private_client import (
    HuobiSyncQueryer,
    HuobiAsyncQueryer,
)

HUOBI_FUTURES_API_HOST = 'api.hbdm.com'


class HuobiSwapNativePrivateClient(object):
  def __init__(self,
               *,
               key_file,
               api_host=None,
               disable_ssl=False,
               timeout=10,
               max_connections=8,
               use_async=False,
               rest_lib='pycurl'):
    rest_lib = rest_lib or None
    api_host = api_host or HUOBI_FUTURES_API_HOST
    if use_async:
      self._auth_queryer = HuobiAsyncQueryer(key_file,
                                             api_host=api_host,
                                             disable_ssl=disable_ssl,
                                             timeout=timeout,
                                             max_connections=max_connections,
                                             rest_lib=rest_lib)
    else:
      self._auth_queryer = HuobiSyncQueryer(key_file, api_host=api_host, timeout=timeout)

  def _query(self, method, path, params=None):
    return self._auth_queryer.query(method, path, params=params)

  def query_account_info(self, symbol=None):
    method = 'POST'
    url = '/swap-api/v1/swap_account_info'
    params = {
        "contract_code": symbol,
    }
    update = self._query(method, url, params)
    return update

  def query_usdt_account_info(self, symbol=None):
    method = 'POST'
    url = '/linear-swap-api/v1/swap_account_info'
    params = {
        "contract_code": symbol,
    }
    update = self._query(method, url, params)
    return update

  def query_cross_usdt_account_info(self, symbol=None):
    method = 'POST'
    url = '/linear-swap-api/v1/swap_cross_account_info'
    params = {
        "contract_code": symbol,
    }
    update = self._query(method, url, params)
    return update

  def query_position_info(self, symbol=None):
    method = 'POST'
    url = '/swap-api/v1/swap_position_info'
    params = {
        "contract_code": symbol,
    }
    update = self._query(method, url, params)
    return update

  def query_usdt_position_info(self, symbol=None):
    method = 'POST'
    url = '/linear-swap-api/v1/swap_position_info'
    params = {
        "contract_code": symbol,
    }
    update = self._query(method, url, params)
    return update
  
  def query_cross_usdt_position_info(self, symbol=None):
    method = 'POST'
    url = '/linear-swap-api/v1/swap_cross_position_info'
    params = {
        "contract_code": symbol,
    }
    update = self._query(method, url, params)
    return update
